	subroutine surfzone(mtmp)
      include 'cst.inc'
      integer mtmp
c
c   sediment fluxes are volume fluxes because the parameter gfact
c   includes the immersed weight and porosity conversions. this routine
c   determines the total sediment fluxes qx for the cells
c   along the shore that represent the wave-driven surf zone. only
c   the last (upper) cell in each column is used to represent the surf zone.
c   longshore transport passes to adjacent cells whether they share
c   a common side or just a corner. cross-shore transport to the offshore
c   occurs only on the 'seaward' face of the cell and is set in subroutine
c   shelfqs. 
c
c   to define the breaker angle picture an "s-shaped" shoreline generally
c   trending east to west with land above and ocean below.  assume the
c   bottom of this map is straight, east-west and the lower grid boundary.
c   the bottom left corner is the origin of the x,y coordinates (also the 
c   i,j coordinates). where the shoreline parallels the lower boundary the
c   initial value of ab is zero.  where the shoreline slopes further away
c   from the bottom boundary going to the right (west) ab is positive. 
c   elsewise it is negative.
c
c   the longshore drift is taken to have both a generally back-and-forth
c   component of transport that disperses sediment from the headlands to
c   the embayments and is a relative magnitude set by mfact. there is also
c   a net component with a magnitude controlled by nfact. spatial gradient
c   of this component also control shoreline development.these factors
c   are proportional to the corresponding wave enery density.
c   they are most easily set by trial and error to get longshore drifts
c   that are correct according to field data.	mfact is often a factor of
c   2 to 10 times the value of nfact.
c
c   the default conditions is to have both wave components progating directly
c   away from the bottom grid boundary so the initial direction of the
c   general wave climate central tendency acent and the direction of the
c   dominant storm waves astorm are both zero.  these are input at the 
c   beginning of the main program and either can be changed.  
c
c   for longshore transport derivation see komar, 1976, p.205.(p392 of Komar 1998)
c   nfact & mfact are time-averaged deep water wave energy densities
c
c?????????????????????????The boundary flow is not considered here
	do i=1,imax-1
	   !abb is the breaker angle at the face of two cells along the shoreline direction
	   abb = 0.5*(ab(i)+ab(i+1))  !*3.14159/180.
	   !qx1 is the sediment transport along the shoreline, proportional to the slope of the shoreline in the x-direction 
	   qx1= nfact*(yshore(i+1)-yshore(i))/deltax !This calculation needs to be generalized (7/24/2009)
	   !qx2 is the net sediment transport based on the power equivanent wave theory 
	   qx2=-mfact*shoal(i)*gfact*(sin(abb))*(cos(abb))
	   !qlit is the sediment transport at the right side face of each cell
   	   qlit(i)=qx1+qx2
c
c     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	   if(mtmp.gt.1.or.i.gt.1)then 
	     qlit(i) = qlit(i)  +((float(i))*qinc)
         else
	     qinc= 0. !(qxrt(i,j))/5
	     qlit(i) = qlit(i)  +((float(i))*qinc)
	   endif  
c
c    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
c	if(i.ne.50)goto 30
c	write(*,*)'qxrt(48)=',qxrt(i-2,j),' qxrt(49)=', qxrt(i-1,j),
c	.' qxrt(50)=',qxrt(i,j)
c    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   	  	
c     
c	if(i.gt.1) then
c	abb = ab(i)+ab(i-1)
c	write(88,*)'i=',i-1,' ab=',ab(i)*180/3.14159,' q=',qlit(i),
c	.' dq=',qlit(i)-qlit(i-1)
c	endif
  	enddo
c	write(88,*)
c	pause
c	do 90 kl=1,2
c      do 40 i=3,imax-2
c40	qq(i) = (qlit(i-1)+qlit(i)+qlit(i+1))/3.
c	do 50 i=3,imax-2
c50	qlit(i)=qq(i)
c90	continue
c
c   there will be a croos shore exchange of sediment between the surf 
c   zone cell and the next ocean cell (a transition cell).  this
c   exchange is governed by the offshore bottom slope. see subroutine
c   exner for how this is handled.
c
c   the surf zone can also be interupted by tidal inlets and river mouths.
c   these are handled in subroutines river and asmita.
c
	return
	end